package my.mall.front.api.util

import my.mall.common.annotation.Slf4j
import my.mall.common.annotation.Slf4j.Companion.log
import my.mall.db.entity.*

@Slf4j
object OrderUtils {
    fun canPayment(userId: Long, order: Order?): Boolean {
        if (order == null) {
            log.warn("userId=[{}],order is null", userId)
            return false
        }
        if (order.orderStatus == null) {
            log.warn("userId=[{}],orderId=[{}],orderStatus is null", userId, order.id)
            return false
        }
        if (userId != order.userId) {
            log.warn("userId=[{}],orderId=[{}],userId failed", userId, order.id)
            return false
        }
        return order.orderStatus!!.toInt() == 1
    }

    fun statusToStr(order: Order?): String {
        if (order?.orderStatus == null) {
            return ""
        }
        if (order.orderStatus!!.toInt() == 0) {
            return "待付款"
        } else if (order.orderStatus!!.toInt() == 1) {
            return "待发货"
        } else if (order.orderStatus!!.toInt() == 2) {
            return "已发货"
        } else if (order.orderStatus!!.toInt() == 3) {
            return "已收货"
        }
        return ""
    }

    fun changeToWaitDelivery(order: Order?): Byte {
        if (order == null) {
            OrderUtils.log.warn("order is null")
            return -1
        }
        if (order.orderStatus == null) {
            log.warn("orderId=[{}],orderStatus is null", order.id)
            return -1
        }
        return if (order.orderStatus!!.toInt() != 0) {
            -1
        } else 1
    }

    fun waitPayment(order: Order): Boolean {
        if (order.orderStatus == null) {
            OrderUtils.log.warn("orderId=[{}],orderStatus is null", order.id)
            return false
        }
        return order.orderStatus!!.toInt() == 1
    }

    fun isRewardPoint(paymentType: String): Boolean {
        return "reward" == paymentType
    }
}
